package com.sghy.xcxservice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sghy.xcxservice.dto.RoomListVo;
import com.sghy.xcxservice.entity.BgbRoom;
import com.sghy.xcxservice.service.BgbRoomService;
import com.sghy.xcxservice.mapper.BgbRoomMapper;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.sghy.xcxservice.common.TokenInterceptor.getUid;

/**
* @author pc
* @description 针对表【bgb_room】的数据库操作Service实现
* @createDate 2025-05-30 16:11:31
*/
@Service
public class BgbRoomServiceImpl extends ServiceImpl<BgbRoomMapper, BgbRoom>
    implements BgbRoomService{

    @Override
    public boolean isProjectNumberExists(String projectNumber) {
        // 使用 MyBatis-Plus 的 lambda 查询方式
        return this.lambdaQuery()
                .eq(BgbRoom::getRoomNo, projectNumber)
                .count() > 0;
    }

    @Override
    public void createProject(String projectName, String projectNumber) {
        BgbRoom bgbRoom = new BgbRoom();
        bgbRoom.setName(projectName);
        bgbRoom.setRoomNo(projectNumber);
        bgbRoom.setUId(getUid());
        this.save(bgbRoom);
    }

    @Override
    public List<RoomListVo> getProjectList(int page, int size, String like) {
        return baseMapper.getProjectList((page-1)*size,size,like);
    }

    @Override
    public RoomListVo getProjectInfo(String roomNo) {
        return baseMapper.getProjectInfo(roomNo);
    }
    
    @Override
    public BgbRoom getByRoomNo(String roomNo) {
        return this.lambdaQuery()
                .eq(BgbRoom::getRoomNo, roomNo).one();
    }
    
}




